﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DWGdirect.DatabaseServices;

using FXnaGis;

using DotSpatial.Topology;



namespace FXnaCAD
{
    public class FXnaGisWriter:BaseWriter
    {


        public FXnaGisWriter()
        {
 
        }



        Dictionary<string, FTransformedVectorLayer> _dicGisLayers = new Dictionary<string, FTransformedVectorLayer>();

        public Dictionary<string, FTransformedVectorLayer> DicGisLayers
        {
            get { return _dicGisLayers; }
            
        }



        public override void InitLayers(System.Collections.Generic.List<string> layers)
        {
            //先调用基类函数

            base.InitLayers(layers);

            foreach (string layerId in layers)
            {
                FTransformedVectorLayer tran = new FTransformedVectorLayer(layerId);

                this._dicGisLayers.Add(layerId,tran);
                
            }




        }





        public override void WriteEntity(Line line)
        {
            
            
            Coordinate c1=GisShapeHelper.ToCoord(line.StartPoint);

            Coordinate c2=GisShapeHelper.ToCoord (line.EndPoint);

            List<Coordinate> coords=new List<Coordinate> ();
            coords.Add (c1);
            coords.Add (c2);

            FLineShape ls = new FLineShape(line.Id.ToString (),coords);

            this._dicGisLayers[line.Layer].AddShape(ls);




        }

        public override void WriteEntity(Polyline poly)
        {
            int num = poly.NumberOfVertices;

            List<Coordinate> coords = new List<Coordinate>();

           

            for (int i = 0; i < num; i++)
            {

                Coordinate c=GisShapeHelper.ToCoord ( poly.GetPoint3dAt(i));


                coords.Add(c);


               
            }

            if (poly.Closed)
            {

                Coordinate c = GisShapeHelper.ToCoord(poly.GetPoint3dAt(0));


                coords.Add(c);

               
            }

            


            FLineShape ls = new FLineShape(poly.Id.ToString(), coords);

            this._dicGisLayers[poly.Layer].AddShape(ls);

            
        }

        public override void WriteEntity(Ellipse ell)
        {
            


        }


        public override void WriteEntity(DBText text)
        {
          
            //关于离散化标注

            FTextShape ts = new FTextShape(text.Id.ToString());
            ts.Text = text.TextString;

            ts.Postion = GisShapeHelper.ToCoord(text.Position);

             ts.Height=  text.Height;
           

            this._dicGisLayers[text.Layer].AddShape(ts);


        }

       
    }
}
